The present invention relates to computer systems and, more particularly, to a method and article for managing references between objects in memories of different durations in a run-time environment.
A dynamic run-time environment for a language such as JAVA(trademark) is responsible for managing memory for objects that are created and destroyed during the execution of a program. An object is an entity that encapsulates data and, in some languages, operations associated with the object. Since the encapsulated data is stored in memory, objects are associated with particular regions of memory that are allocated and deallocated by the dynamic run-time environment.
The state of a program, or xe2x80x9cprogram state,xe2x80x9d is the set of the objects and the references between the objects that exist at a specific point in time during the execution of the program. A xe2x80x9creferencexe2x80x9d is used by a run-time environment to identify and ultimately access the region of memory for storing the data of the object. Typically, references between objects in a run-time environment are encoded using machine pointers. A machine pointer is a native datum that contains the address of the object in the main memory, which can be a real memory address or, more commonly, a virtual address on a machine that implements a virtual memory system.
xe2x80x9cVirtual memoryxe2x80x9d refers to memory addressable by a storage allocation technique in which auxiliary storage, such as memory on a hard disk, can be addressed as though it were part of the main memory such as a RAM. More specifically, combinations of hardware, firmware, and operating system cooperate to automatically swap portions of the code and data for an executing process on an as-needed basis. Thus, the virtual address space may be regarded as addressable main memory to a process executing on a computer system that maps virtual addresses into real addresses. The size of the virtual address space is usually limited by the size of a native machine pointer, but not by the actual number of storage elements in main memory.
A virtual address space is typically subdivided into a plurality of fixed-size contiguous sections of memory called xe2x80x9cpages.xe2x80x9d Typically, some of the virtual memory pages for a process are specific to the process and cannot be shared with other processes, but, in some implementations, other virtual memory pages can be shared globally with other processes.
One popular run-time environment is a JAVA(trademark) virtual machine, which supports a platform-independent, object-oriented language developed by Sun Microsystems. In JAVA, the attributes and methods for a class of objects are typically defined in a source file, which is compiled into an architecture-neutral object file containing bytecodes that are interpreted in the virtual machine at the target platform. It is common for objects to reference other objects.
Lately, there has been much interest in using JAVA in a multi-user environment that allows multiple users to connect in separate, concurrent sessions to a server system, such as a relational database system. When designing a run-time environment for such a multi-user environment, scalability in terms of the number of simultaneous users who can establish separate sessions is very important.
A significant constraint for user scalability is the size of the memory xe2x80x9cfootprintxe2x80x9d that each session consumes. For example, a server system may have 100 Mb of memory for supporting all the user sessions. If the session memory footprint is 1 Mb, then only 100 user sessions can be supported at one time. Therefore, it is desirable to reduce the session memory footprint to improve scalability.
One approach for reducing the session memory footprint in a run-time environment is to allocate a single copy of objects, code, and data in a globally shared memory rather than in a session memory that is devoted to a single session. In the example, if 500 Kb of the 1 Mb session memory footprint can be shared between the different sessions, then 500 Kb of the total 100 Mb can be reserved as a global shared memory, and the remaining the 99.5 Mb would available for the individual session memories. Since the session memory requirements has dropped to 500 Kb, a total of 199 user sessions can now be supported. Consequently, session memory reduction by using globally shared memory is a promising approach for improving scalability of the multi-user run-time environment.
The globally shared memory approach cannot be easily applied for a large object wherein most of the object is potentially sharable, but some part of the object has a pointer to session-specific state. Since the value of the pointer varies from session to session, that value cannot be placed in a globally shared memory. Therefore, the large object cannot be placed in the globally shared memory as-is. Obviously, one way to address the difficulty associated with the shared object with a reference to a private object is to simply avoid putting such objects in the globally shared memory, thereby surrendering the benefits of session memory reduction, including user scalability.
Therefore, an indexing scheme has been developed, in which the large object is indeed placed in the global memory, but the reference to the session-private object is replaced with an index that is common to all the sessions. Each session contains a corresponding table that stores references to session-private objects at entries corresponding to the same index value. When this reference to the session-private object in the large object is deferenced, the index is used to identify the entry in the table to obtain the actual reference or pointer to the session-private object.
A drawback with this indexing scheme, however, is that finding the location of the table in the session memory can be expensive, thereby adversely affecting system performance of the run-time environment. For example, if the address of the table is maintained in a system hash table, the hash table lookup is an expensive computation, requiring a function call and many memory dereferencing operations. Therefore, there is a need for a computationally inexpensive procedure to locate the table of session-specific references from a globally shared object.
This and other needs are addressed by the present invention by having the virtual memory manager arrange for the shared and unshared pages to be allocated in such a way that the table of session-specific references can easily be located by performing an arithmetic operation on a pointer to an object in the shared memory. Consequently, performance is improved because expensive operations such as a function call or several deferences are avoided.
For example, contiguous virtual memory pages used by a session can be allocated in an aligned segment that comprises at least one unshared memory page (that holds the table of references to the session-specific objects) at a predetermined offset and a shared memory page. To reach the session-specific object from a shared object, a pointer to the shared object is masked to find the beginning of the segment, and the predetermined offset plus the offset to the table is then added to mask pointer to calculate the address of the table.
Accordingly, one aspect of the invention relates to a method and software for managing a run-time environment, in which multiple pages in a contiguous virtual address space are allocated. A predetermined page (such as the first page) is assigned to unshared memory, while at least one of the other pages is assigned to shared memory. The session-specific object, a reference to the object, a table containing a reference to an session-specific object, or a pointer to the table, or other indirect reference to the object, is stored in the predetermined page, and the shared object contains an index possibly encoded into the table for referencing the session-specific object.
Another aspect of the invention pertains to a method and software for accessing an session-specific object in an unshared memory that is referenced by a shared object in a shared memory. A pointer to the shared object is masked to produce a masked pointer that is, for example, aligned to the beginning of an aligned set of pages. The session-specific object is accessed based on the masked pointer, for example, through a table containing a reference to an session-specific object.
Still other objects and advantages of the present invention will become readily apparent from the following detailed description, simply by way of illustration of the best mode contemplated of carrying out the invention. As will be realized, the invention is capable of other and different embodiments, and its several details are capable of modifications in various obvious respects, all without departing from the invention. Accordingly, the drawing and description are to be regarded as illustrative in nature, and not as restrictive.